package com.Base;

import com.alibaba.druid.support.json.JSONUtils;
import com.github.pagehelper.PageInfo;
import org.apache.log4j.Logger;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.util.Factory;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by XingYang on 2019/2/27.
 */
public class BaseServlet {

      public  final transient Logger log = Logger.getLogger(this.getClass());
      public  final Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
      public   final SecurityManager securityManager = factory.getInstance();


      public String sendResponse(String resultCode, String msg, Map paramMap){
            HashMap resp = new HashMap<>();
            resp.put("result",resultCode);
            resp.put("msg",msg);
            resp.put("params",paramMap);
            return JSONUtils.toJSONString(resp);
      }
      public String sendPageResponse(String resultCode, String msg, PageInfo pageInfo){
            HashMap resp = new HashMap<>();
            Map map = new HashMap();

            map.put("pages",pageInfo.getPages());//总页数
            map.put("total",pageInfo.getTotal());//总记录数
            map.put("pageNum",pageInfo.getPageNum());

            resp.put("result",resultCode);
            resp.put("msg",msg);
            resp.put("pageInf",map);
            resp.put("params",pageInfo.getList());
            return JSONUtils.toJSONString(resp);
      }



}
